package com.sise.controller;


import com.sise.pojo.Grade;
import com.sise.pojo.Student;
import com.sise.service.GradeService;
import com.sise.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import java.util.UUID;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 彭海霞
 * @since 2020-06-13
 */
@Controller
@RequestMapping("/grade")
public class GradeController {

    @Autowired
    private StudentService studentService;

    @Autowired
    private GradeService gradeService;
    @RequestMapping("/selectGradeAll")
    public String selectGradeAll(Model model) {
        //  参数一：当前页
        //  参数二：页面大小
        //  使用了分页插件之后，所有的分页操作也变得简单的！
        List<Grade> list = gradeService.list(null);
        model.addAttribute("list", list);
        return "grade-list";
    }

    @RequestMapping("/preAddGrade")
    public String preAddGrade(Model model) {
        List<Student> list = studentService.list(null);
        model.addAttribute("list",list);
        return "grade-add";
    }
    @RequestMapping("/addGrade")
    public String addGrade(Grade grade,Model model) {
        boolean save = gradeService.save(grade);
        return "forward:/grade/selectGradeAll";
    }
    @RequestMapping("/selectGradeByGid")
    public String selectGradeByGid(Integer gid,Model model) {
        Grade grade = gradeService.getById(gid);
        model.addAttribute("grade", grade);
        List<Student> list = studentService.list(null);
        model.addAttribute("list",list);
        return "grade-view";
    }
    @RequestMapping("/updateGrade")
    public String updateGrade(Grade grade) {
        boolean b = gradeService.updateById(grade);
        return "forward:/grade/selectGradeAll";
    }
    @RequestMapping("/deleteGrade")
    public String deleteGrade(Integer gid) {
        boolean b = gradeService.removeById(gid);
        return "forward:/grade/selectGradeAll";
    }
}

